package Assignment;

import java.util.Scanner;

public class Test6 {
    public static void main(String[] args) {

        //arr数组是大小先排序好的
        int[] arr = {12, 14, 23, 45, 66, 68, 70, 77, 90, 91};

        int[] newArrr = new int[arr.length + 1];

        Scanner scanner = new Scanner(System.in);
        System.out.print("输入一个整数：");
        int number = scanner.nextInt();

        //变量代表要插入的位置
        int index = 0;

        for (int i = 0; i < arr.length; i++) {
            if (arr[i] <= number) {
                //如果元素小于或等于要插入的数字，则直接存放
                newArrr[i] = arr[i];
                //把i后面的数字记录下来
                index = i+1;
            }else {
                //如果元素大于要插入的数字，则往后一个放
                newArrr[i + 1] = arr[i];//这里的i与index相等
            }
        }
        //index存储的值就是要插入的位置
        newArrr[index] = number;
        for (int i = 0; i < newArrr.length; i++) {
            System.out.print(newArrr[i] + " ");
        }


    }
}
